class ReplicaSystem < ActiveRecord::Base
  has_many :replicas
  
  # Constants of supported protocols by Replica Systems
  Local = "Local"
  FTP   = "FTP"
  HTTP  = "HTTP"
  SMB   = "SMB"
  
  # Returns the ReplicaSystem that is the Main Repository to the System
  def self.find_main_repository
    begin
      ReplicaSystem.find :first, :conditions => { :main => true }
    rescue RecordNotFound
      nil
    end
  end
  
  # Returns the path to store files in Main Repository
  def self.main_repository_path
    main = find_main_repository
    (main.hostname + main.internal_uri) unless main.nil?
  end
  
  def require_authentication?
    !(self.username.nil? or self.username.blank?)
  end
  
  def has_internal_uri?
    !(self.internal_uri.nil? or self.internal_uri.blank?)
  end
end